package com.ibeeking.gmc.global.g.rest.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ibeeking.found.common.entity.open.OpenConfigDTO;
import com.ibeeking.found.common.entity.open.OpenConfigOfExtend;
import com.ibeeking.found.common.entity.open.OpenConfigQuery;
import com.ibeeking.found.common.enums.*;
import com.ibeeking.found.common.utils.DateUtils;
import com.ibeeking.found.common.utils.UserUtils;
import com.ibeeking.gmc.global.g.rest.service.IOpenConfigService;
import com.ibeeking.gmc.global.g.rest.service.IWxOpenService;
import com.ibeeking.gmc.global.service.common.dos.OpenConfigDO;
import com.ibeeking.gmc.global.service.common.enums.WxOpenMaTemplateTypeEnum;
import com.ibeeking.gmc.global.service.common.param.OpenConfigParam;
import com.ibeeking.gmc.global.service.common.query.OpenConfigPageQuery;
import com.ibeeking.gmc.global.service.common.vo.OpenConfigVO;
import com.ibeeking.gmc.global.service.common.vo.WxOpenMaGeneralTemplateVO;
import com.ibeeking.gmc.global.service.common.vo.WxOpenMaStandardTemplateVO;
import com.ibeeking.gmc.global.service.common.vo.WxOpenMaTemplateDraftVO;
import com.ibeeking.gmc.global.service.mapper.OpenConfigMapper;
import com.ibeeking.nematos.core.utils.SpringBeanUtil;
import com.ibeeking.nematos.exception.BusinessException;
import com.ibeeking.nematos.log.utils.LogUtils;
import com.ibeeking.nematos.utils.bean.BeanUtil;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.json.JsonUtils;
import me.chanjar.weixin.open.api.WxOpenComponentService;
import me.chanjar.weixin.open.api.WxOpenService;
import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName OpenConfigServiceImpl
 * @Description
 * @Author ibeeking
 * @Date 2021-06-16 16:06
 **/
@Service
public class OpenConfigServiceImpl extends ServiceImpl<OpenConfigMapper, OpenConfigDO> implements IOpenConfigService {

    @Resource
    private OpenConfigMapper openConfigMapper;

    @Resource
    private IWxOpenService wxOpenServiceImpl;

    /**
     * 查询在第三方平台配置的公众信息
     *
     * @param query
     * @return
     */
    @Override
    public Page<OpenConfigVO> pageList(OpenConfigPageQuery query) {
        List<OpenConfigVO> resultVOS = null;
        LambdaQueryWrapper<OpenConfigDO> queryWrapper = new LambdaQueryWrapper<>(OpenConfigDO.class)
                .eq(query.getId()!= null, OpenConfigDO::getId, query.getId())
                .eq(query.getType()!= null, OpenConfigDO::getType, query.getType())
                .eq(query.getSubType()!= null, OpenConfigDO::getSubType, query.getSubType())
                .eq(StringUtils.isNotBlank(query.getOpenAppId()), OpenConfigDO::getOpenAppId, query.getOpenAppId())
                .eq(StringUtils.isNotBlank(query.getComponentAppId()), OpenConfigDO::getComponentAppId, query.getComponentAppId())
                .like(StringUtils.isNotBlank(query.getName()), OpenConfigDO::getName, query.getName())
                .eq(query.getPublishStatus() != null, OpenConfigDO::getPublishStatus, query.getPublishStatus());
        Page<OpenConfigDO> pagesDOS = openConfigMapper.selectPage(new Page<>(query.getPageNum(), query.getPageSize()), queryWrapper);
        if((pagesDOS !=null) && (pagesDOS.getSize()>0)){
            resultVOS = pagesDOS.getRecords().stream().map(obj -> {
                OpenConfigVO openConfigVO = BeanUtil.convertBean(obj, OpenConfigVO.class);
                openConfigVO.setTypeName(OpenApiConfigEnum.getValueByCode(obj.getType()));

                if(obj.getCreateTime() != null){
                    openConfigVO.setCreateTime(DateUtils.localDateTimeToStr(obj.getCreateTime()));
                }
                String extendJson = obj.getExtendJson();
                if(StringUtils.isNotEmpty(extendJson)) {
                    OpenConfigOfExtend openConfigOfExtend = JsonUtils.fromJson(extendJson, OpenConfigOfExtend.class);
                    openConfigVO.setOpenConfigOfExtend(openConfigOfExtend);
                }
                if(obj.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_WECHAT_OPEN.getCode()) {
                    openConfigVO.setSubTypeName(WxOpenAppTypeEnum.getValueByCode(obj.getSubType()));
                } else if(obj.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_WECHAT_CP.getCode()) {
                    openConfigVO.setSubTypeName(WxCpAppTypeEnum.getValueByCode(obj.getSubType()));
                } else if(obj.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_ALIPAY_OPEN.getCode()) {
                    openConfigVO.setSubTypeName(AliPayOpenAppTypeEnum.getValueByCode(obj.getSubType()));
                } else if(obj.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_DINGTALK_OPEN.getCode()) {
                    openConfigVO.setSubTypeName(AliDingTalkAppTypeEnum.getValueByCode(obj.getSubType()));
                }
               return openConfigVO;
              }
            ).collect(Collectors.toList());
        }
        Page<OpenConfigVO> pagesVO = new Page<OpenConfigVO>().setRecords(resultVOS).setTotal(pagesDOS.getTotal());
        return pagesVO;
    }
    /**
     * 查询在第三方平台配置的信息
     *
     * @param query
     * @return
     */
    @Override
    public List<OpenConfigVO> list(OpenConfigQuery query) {
        List<OpenConfigVO> resultVO = null;
        List<OpenConfigDO> warehouseDOs = openConfigMapper.selectList(new LambdaQueryWrapper<OpenConfigDO>()
                .eq(query.getId()!= null, OpenConfigDO::getId, query.getId())
                .eq(query.getType()!= null, OpenConfigDO::getType, query.getType())
                .eq(query.getSubType()!= null, OpenConfigDO::getSubType, query.getSubType())
                .eq(StringUtils.isNotBlank(query.getOpenAppId()), OpenConfigDO::getOpenAppId, query.getOpenAppId())
                .eq(StringUtils.isNotBlank(query.getComponentAppId()), OpenConfigDO::getComponentAppId, query.getComponentAppId())
                .like(StringUtils.isNotBlank(query.getName()), OpenConfigDO::getName, query.getName())
                .eq(query.getPublishStatus() != null, OpenConfigDO::getPublishStatus, query.getPublishStatus())
        );
        List<OpenConfigVO> openConfigVOS = JsonUtils.jsonToList(warehouseDOs, OpenConfigVO.class);
        if(Collections3.isNotEmpty(openConfigVOS)){
            resultVO = openConfigVOS.stream().map(entityVO -> {
                OpenConfigVO openConfigVO = BeanUtil.convertBean(entityVO, OpenConfigVO.class);
                openConfigVO.setTypeName(OpenApiConfigEnum.getValueByCode(entityVO.getType()));
                String extendJson = entityVO.getExtendJson();
                if(StringUtils.isNotEmpty(extendJson)) {
                    OpenConfigOfExtend openConfigOfExtend = JsonUtils.fromJson(extendJson, OpenConfigOfExtend.class);
                    openConfigVO.setOpenConfigOfExtend(openConfigOfExtend);
                }
                if(entityVO.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_WECHAT_OPEN.getCode()) {
                    openConfigVO.setSubTypeName(WxOpenAppTypeEnum.getValueByCode(entityVO.getSubType()));
                } else if(entityVO.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_WECHAT_CP.getCode()) {
                    openConfigVO.setSubTypeName(WxCpAppTypeEnum.getValueByCode(entityVO.getSubType()));
                } else if(entityVO.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_ALIPAY_OPEN.getCode()) {
                    openConfigVO.setSubTypeName(AliPayOpenAppTypeEnum.getValueByCode(entityVO.getSubType()));
                } else if(entityVO.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_DINGTALK_OPEN.getCode()) {
                    openConfigVO.setSubTypeName(AliDingTalkAppTypeEnum.getValueByCode(entityVO.getSubType()));
                }
                return openConfigVO;
            }).collect(Collectors.toList());
        }
        return resultVO;
    }
    /**
     * 查询在第三方平台配置的信息
     *
     * @param query
     * @return
     */
    @Override
    public List<OpenConfigDTO> queryOpenConfigList(OpenConfigQuery query) {
        List<OpenConfigDTO> resultDTO = null;
        List<OpenConfigDO> warehouseDOs = openConfigMapper.selectList(new LambdaQueryWrapper<OpenConfigDO>()
                .eq(query.getId()!= null, OpenConfigDO::getId, query.getId())
                .eq(query.getType()!= null, OpenConfigDO::getType, query.getType())
                .eq(query.getSubType()!= null, OpenConfigDO::getSubType, query.getSubType())
                .eq(StringUtils.isNotBlank(query.getOpenAppId()), OpenConfigDO::getOpenAppId, query.getOpenAppId())
                .eq(StringUtils.isNotBlank(query.getComponentAppId()), OpenConfigDO::getComponentAppId, query.getComponentAppId())
                .like(StringUtils.isNotBlank(query.getName()), OpenConfigDO::getName, query.getName())
                .eq(OpenConfigDO::getPublishStatus, PublishStatusEnum.ENABLE.getValue())
        );
        List<OpenConfigDTO> openConfigVOS = JsonUtils.jsonToList(warehouseDOs, OpenConfigDTO.class);
        if(Collections3.isNotEmpty(openConfigVOS)){
            resultDTO = openConfigVOS.stream().map(entityVO -> {
                OpenConfigDTO openConfigDTO = BeanUtil.convertBean(entityVO, OpenConfigDTO.class);
                String extendJson = entityVO.getExtendJson();
                if(StringUtils.isNotEmpty(extendJson)){
                    OpenConfigOfExtend openConfigOfExtend = JsonUtils.fromJson(extendJson,OpenConfigOfExtend.class);
                    if(openConfigOfExtend!=null){
                        openConfigDTO.setOpenConfigOfExtend(openConfigOfExtend);
                    }
                }
                return openConfigDTO;
            }).collect(Collectors.toList());
        }
        return resultDTO;
    }

    /**
     * 查询在第三方平台配置的公众信息
     *
     * @param query
     * @return
     */
    @Override
    public OpenConfigDTO queryOpenConfigOne(OpenConfigQuery query){
        OpenConfigDO entityDO = openConfigMapper.selectOne(new LambdaQueryWrapper<OpenConfigDO>()
                .eq(query.getId()!= null, OpenConfigDO::getId, query.getId())
                .eq(query.getType()!= null, OpenConfigDO::getType, query.getType())
                .eq(query.getSubType()!= null, OpenConfigDO::getSubType, query.getSubType())
                .eq(StringUtils.isNotBlank(query.getOpenAppId()), OpenConfigDO::getOpenAppId, query.getOpenAppId())
                .eq(StringUtils.isNotBlank(query.getComponentAppId()), OpenConfigDO::getComponentAppId, query.getComponentAppId())
                .like(StringUtils.isNotBlank(query.getName()), OpenConfigDO::getName, query.getName())
                .eq(OpenConfigDO::getPublishStatus, PublishStatusEnum.ENABLE.getValue())
        );
        if(entityDO != null){
            OpenConfigDTO entityVO = BeanUtil.convertBean(entityDO, OpenConfigDTO.class);
            String extendJson = entityDO.getExtendJson();
            if(StringUtils.isNotEmpty(extendJson)){
                OpenConfigOfExtend openConfigOfExtend = JsonUtils.fromJson(extendJson,OpenConfigOfExtend.class);
                if(openConfigOfExtend!=null){
                    entityVO.setOpenConfigOfExtend(openConfigOfExtend);
                }
            }
            return entityVO;
        }
        return null;
    }

    /**
     * 根据id查看详情
     *
     * @param id
     * @return
     */
    @Override
    public OpenConfigVO view(Long id) {
        OpenConfigDO openConfigDO = this.openConfigMapper.selectById(id);
        if(openConfigDO == null) throw new BusinessException("记录不存在！");
        if(openConfigDO !=null) {
            OpenConfigVO openConfigVO =  BeanUtil.convertBean(openConfigDO, OpenConfigVO.class);
            openConfigVO.setTypeName(OpenApiConfigEnum.getValueByCode(openConfigDO.getType()));
            String extendJson = openConfigDO.getExtendJson();
            if(StringUtils.isNotEmpty(extendJson)) {
                OpenConfigOfExtend openConfigOfExtend = JsonUtils.fromJson(extendJson, OpenConfigOfExtend.class);
                if (openConfigOfExtend != null) {
                    openConfigVO.setOpenConfigOfExtend(openConfigOfExtend);
                }
            }
            if(openConfigDO.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_WECHAT_OPEN.getCode()) {
                openConfigVO.setSubTypeName(WxOpenAppTypeEnum.getValueByCode(openConfigDO.getSubType()));
            } else if(openConfigDO.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_WECHAT_CP.getCode()) {
                openConfigVO.setSubTypeName(WxCpAppTypeEnum.getValueByCode(openConfigDO.getSubType()));
            } else if(openConfigDO.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_ALIPAY_OPEN.getCode()) {
                openConfigVO.setSubTypeName(AliPayOpenAppTypeEnum.getValueByCode(openConfigDO.getSubType()));
            } else if(openConfigDO.getType() == OpenApiConfigEnum.OPEN_CONFIG_TYPE_DINGTALK_OPEN.getCode()) {
                openConfigVO.setSubTypeName(AliDingTalkAppTypeEnum.getValueByCode(openConfigDO.getSubType()));
            }

        return openConfigVO;
        }else{
            return null;
        }
    }

      @Override
    public WxOpenService getWxOpenService() {
        WxOpenService wxOpenService = SpringBeanUtil.getBean(WxOpenService.class);
        if(wxOpenService == null) throw new BusinessException("get WxOpenService service error!");
        return wxOpenService;
    }

    @Override
    public List<WxOpenMaTemplateDraftVO> getWxOpenMaTemplateDraftList(String configId){
        try {
            if(StringUtils.isEmpty(configId)) throw new BusinessException("读取configId错误");
            List<WxOpenMaTemplateDraftVO> wxOpenMaTemplateDraftVOS = Collections3.emptyList();

            WxOpenService wxOpenService = wxOpenServiceImpl.getWxOpenService(Long.valueOf(configId));
            if(wxOpenService == null){
                throw new BusinessException("获取微信开放台服务出错!");
            }
            WxOpenComponentService wxOpenComponentService = wxOpenService.getWxOpenComponentService();

            List<WxOpenMaCodeTemplate> wxOpenMaCodeTemplateS = wxOpenComponentService.getTemplateDraftList();
            LogUtils.info(">>>>>>wxOpenMaCodeTemplateS:{}>>>>>",JsonUtils.toJsonStr(wxOpenMaCodeTemplateS));
            wxOpenMaTemplateDraftVOS = wxOpenMaCodeTemplateS.parallelStream().map(d->{
                WxOpenMaTemplateDraftVO wxOpenMaTemplateDraftVO = BeanUtil.convertBean(d, WxOpenMaTemplateDraftVO.class);
                LogUtils.info(">>>>>>wxOpenMaTemplateDraftVO:{}>>>>>",JsonUtils.toJsonStr(wxOpenMaTemplateDraftVO));
                if(d.getCreateTime() !=null) {
                    LocalDateTime createTime = DateUtils.longToLocalDateTime(d.getCreateTime());
                    DateTimeFormatter formater = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
                    String createTimeStr = formater.format(createTime);
                    wxOpenMaTemplateDraftVO.setCreateTimeName(createTimeStr);
                }
                wxOpenMaTemplateDraftVO.setTemplateTypeName(WxOpenMaTemplateTypeEnum.getNameByCode(d.getTemplateType()));
                return wxOpenMaTemplateDraftVO;
            }).collect(Collectors.toList());
            LogUtils.info(">>>>>>wxOpenMaTemplateDraftVOS:{}>>>>>",JsonUtils.toJsonStr(wxOpenMaTemplateDraftVOS));
            return wxOpenMaTemplateDraftVOS;
        }catch(Exception ex){
            LogUtils.error(ex.toString());
            return Collections3.emptyList();
        }
    }

    @Override
    public List<WxOpenMaGeneralTemplateVO> getWxOpenMaGeneralTemplateList(String configId){
        try {
            if(StringUtils.isEmpty(configId)) throw new BusinessException("读取configId错误");
            List<WxOpenMaGeneralTemplateVO> wxOpenMaTemplateVOS = Collections3.emptyList();

            WxOpenService wxOpenService = wxOpenServiceImpl.getWxOpenService(Long.valueOf(configId));
            if(wxOpenService == null){
                throw new BusinessException("获取微信开放台服务出错!");
            }
            WxOpenComponentService wxOpenComponentService = wxOpenService.getWxOpenComponentService();

            List<WxOpenMaCodeTemplate> wxOpenMaCodeTemplateS = wxOpenComponentService.getTemplateList(WxOpenMaTemplateTypeEnum.TEMPLATE_GENERAL.getCode());

            wxOpenMaTemplateVOS = wxOpenMaCodeTemplateS.parallelStream().map(d->{
                WxOpenMaGeneralTemplateVO wxOpenMaTemplateDraftVO = BeanUtil.convertBean(d, WxOpenMaGeneralTemplateVO.class);
                if(d.getCreateTime() !=null) {
                    LocalDateTime createTime = DateUtils.longToLocalDateTime(d.getCreateTime());
                    DateTimeFormatter formater = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
                    String createTimeStr = formater.format(createTime);
                    wxOpenMaTemplateDraftVO.setCreateTimeName(createTimeStr);
                }
                wxOpenMaTemplateDraftVO.setTemplateTypeName(WxOpenMaTemplateTypeEnum.getNameByCode(d.getTemplateType()));
                return wxOpenMaTemplateDraftVO;
            }).collect(Collectors.toList());
            return wxOpenMaTemplateVOS;
        }catch(Exception ex){
            LogUtils.error(ex.toString());
            return Collections3.emptyList();
        }
    }

    @Override
    public List<WxOpenMaStandardTemplateVO> getWxOpenMaStandardTemplateList(String configId){
        try {
            if(StringUtils.isEmpty(configId)) throw new BusinessException("读取configId错误");
            List<WxOpenMaStandardTemplateVO> wxOpenMaTemplateVOS = Collections3.emptyList();

            WxOpenService wxOpenService = wxOpenServiceImpl.getWxOpenService(Long.valueOf(configId));
            if(wxOpenService == null){
                throw new BusinessException("获取微信开放台服务出错!");
            }
            WxOpenComponentService wxOpenComponentService = wxOpenService.getWxOpenComponentService();

            List<WxOpenMaCodeTemplate> wxOpenMaCodeTemplateS = wxOpenComponentService.getTemplateList(WxOpenMaTemplateTypeEnum.TEMPLATE_STANDARD.getCode());

            wxOpenMaTemplateVOS = wxOpenMaCodeTemplateS.parallelStream().map(d->{
                WxOpenMaStandardTemplateVO wxOpenMaTemplateVO = BeanUtil.convertBean(d, WxOpenMaStandardTemplateVO.class);
                if(d.getCreateTime() !=null) {
                    LocalDateTime createTime = DateUtils.longToLocalDateTime(d.getCreateTime());
                    DateTimeFormatter formater = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
                    String createTimeStr = formater.format(createTime);
                    wxOpenMaTemplateVO.setCreateTimeName(createTimeStr);
                }
                wxOpenMaTemplateVO.setTemplateTypeName(WxOpenMaTemplateTypeEnum.getNameByCode(d.getTemplateType()));
                return wxOpenMaTemplateVO;
            }).collect(Collectors.toList());
            return wxOpenMaTemplateVOS;
        }catch(Exception ex){
            LogUtils.error(ex.toString());
            return Collections3.emptyList();
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean add(OpenConfigParam openConfigParam) {
        checkOpenConfig(openConfigParam);

        OpenConfigDO openConfigDO = BeanUtil.convertBean(openConfigParam, OpenConfigDO.class);
        openConfigDO.setCreateBy(UserUtils.getUserId());
        openConfigDO.setCreateTime(LocalDateTime.now());
        openConfigDO.setModifyTime(LocalDateTime.now());
        OpenConfigOfExtend openConfigOfExtend = openConfigParam.getOpenConfigOfExtend();
        if(openConfigOfExtend!=null){
            openConfigDO.setExtendJson(JsonUtils.toJsonStr(openConfigOfExtend));
        }

        return openConfigMapper.insert(openConfigDO) > 0;
    }

    /**
     * 修改第三方平台配置列表
     *
     * @param openConfigParam
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean modify(OpenConfigParam openConfigParam) {
        OpenConfigDO openConfigDO = BeanUtil.convertBean(openConfigParam, OpenConfigDO.class);
        openConfigDO.setModifyBy(UserUtils.getUserId());
        openConfigDO.setModifyTime(LocalDateTime.now());
        OpenConfigOfExtend openConfigOfExtend = openConfigParam.getOpenConfigOfExtend();
        if(openConfigOfExtend!=null){
            openConfigDO.setExtendJson(JsonUtils.toJsonStr(openConfigOfExtend));
        }
        return openConfigMapper.updateById(openConfigDO) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean changeStatus(Long id, Integer status, Long modifyBy) {
        OpenConfigDO openConfigDO = openConfigMapper.selectById(id);
        if(openConfigDO == null ) throw new BusinessException("记录不存在!");
        openConfigDO.setPublishStatus(status);
        openConfigDO.setModifyBy(modifyBy);
        openConfigDO.setModifyTime(LocalDateTime.now());
        return openConfigMapper.updateById(openConfigDO) > 0;
    }

    @Override
    public List<Map<String, Object>> queryOpenApiTypeList(){
        List<Map<String, Object>> openApiTypeList= new ArrayList<>();

        for(OpenApiConfigEnum openApiConfig : OpenApiConfigEnum.values()){
            Map<String, Object> openApiConfigMap = new HashMap<>();
            openApiConfigMap.put("key", openApiConfig.getCode());
            openApiConfigMap.put("value", openApiConfig.getValue());
            openApiTypeList.add(openApiConfigMap);
        }
        return openApiTypeList;
    }

    @Override
    public List<Map<String, Object>> queryOpenApiSubTypeList(Integer type){
        List<Map<String, Object>> appTypeList= new ArrayList<>();
        if(type == OpenApiConfigEnum.OPEN_CONFIG_TYPE_WECHAT_OPEN.getCode()) {
            for (WxOpenAppTypeEnum appType : WxOpenAppTypeEnum.values()) {
                Map<String, Object> appTypeMap = new HashMap<>();
                appTypeMap.put("key", appType.getCode());
                appTypeMap.put("value", appType.getValue());
                appTypeList.add(appTypeMap);
            }
        }else if(type == OpenApiConfigEnum.OPEN_CONFIG_TYPE_WECHAT_CP.getCode()){
            for (WxCpAppTypeEnum appType : WxCpAppTypeEnum.values()) {
                Map<String, Object> appTypeMap = new HashMap<>();
                appTypeMap.put("key", appType.getCode());
                appTypeMap.put("value", appType.getValue());
                appTypeList.add(appTypeMap);
            }
        }else if(type == OpenApiConfigEnum.OPEN_CONFIG_TYPE_ALIPAY_OPEN.getCode()){
            for (AliPayOpenAppTypeEnum appType : AliPayOpenAppTypeEnum.values()) {
                Map<String, Object> appTypeMap = new HashMap<>();
                appTypeMap.put("key", appType.getCode());
                appTypeMap.put("value", appType.getValue());
                appTypeList.add(appTypeMap);
            }
        }else if(type == OpenApiConfigEnum.OPEN_CONFIG_TYPE_DINGTALK_OPEN.getCode()){
            for (AliDingTalkAppTypeEnum appType : AliDingTalkAppTypeEnum.values()) {
                Map<String, Object> appTypeMap = new HashMap<>();
                appTypeMap.put("key", appType.getCode());
                appTypeMap.put("value", appType.getValue());
                appTypeList.add(appTypeMap);
            }
        }else if(type == OpenApiConfigEnum.OPEN_CONFIG_TYPE_TIKTOK_TP_OPEN.getCode()){

        }
        return appTypeList;
    }
    /**
     * 根据id删除第三方平台配置列表
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean del(Long id) {
        return openConfigMapper.deleteById(id) > 0;
    }
    /**
     * 校验第三方平台配置唯一性
     *
     * @param openConfigParam
     * @return
     */
    private void checkOpenConfig(OpenConfigParam openConfigParam) {
        QueryWrapper<OpenConfigDO> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(OpenConfigDO::getComponentAppId, openConfigParam.getComponentAppId());
        queryWrapper.lambda().eq(openConfigParam.getOpenAppId() != null, OpenConfigDO::getOpenAppId, openConfigParam.getOpenAppId());
        if (Collections3.isNotEmpty(this.openConfigMapper.selectList(queryWrapper))) {
            throw new BusinessException("应用componentAppId已存在，不能重复！");
        }
    }

    private IOpenConfigService getBean(){
        return SpringBeanUtil.getBean(OpenConfigServiceImpl.class);
    }
}
